// pages/collageDetail/collagePreview.js
// pages/collageDetail/collageDetail.js
var $=require('../util/commit.js');
var imageArr = [];
Page({

  /**
   * 页面的初始数据
   */
  data: {
    collageDage:{},
    sendRequire:{},
    screenWidth: 0,
    screenHeight: 0,
    imageArrH: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;

    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          screenHeight: res.windowHeight,
          screenWidth: res.windowWidth,
        });
      }
    });

    wx.getStorage({
      key: 'ActiveData',
      success: function(res) {
        that.setData({
          collageDage:res.data
        })
      },
    });
    
  },
  imageLoad: function (e) {
    console.log(e.currentTarget.dataset.index);
    let that = this;
    var width = '';
    var height = '';
    var viewHeight = '';    //获取图片真实宽度
    var screenWidth = that.data.screenWidth;
    var screenHeight = that.data.screenHeight;
    let url = e.currentTarget.dataset.url;
    url = url.substring(7);
    url = 'https://' + url;
    console.log(url);
    wx.getImageInfo({
      src: url,
      success: function (res) {
        console.log(res);
        width = res.width;
        height = res.height;
        let ratio = width / height;   //图片的真实宽高比例
        viewHeight = screenWidth / ratio * 2;    //计算的高度值   
        imageArr[e.currentTarget.dataset.index] = viewHeight;
        console.log(imageArr);
        that.setData({
          imageArrH: imageArr,
        })
      },
      fail: function (res) {
        console.log(res);
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 我要报名
  BMBtn:function(e){
    let that = this;
   
    let contentTxt = JSON.stringify(that.data.collageDage.content);
    $.POST({
      url: 'caRC',
      data: {
        title: that.data.collageDage.title,
        pic_id: that.data.collageDage.pic_id,
        collage_id: that.data.collageDage.collage_id,
        collage_number: that.data.collageDage.collage_number,
        register_end_time: '',
        begin_time: that.data.collageDage.dateStartTimeVal,
        end_time: that.data.collageDage.dateEndTimeVal,
        type: that.data.collageDage.type,
        price_id: that.data.collageDage.price_id,
        address: that.data.collageDage.address,
        detailed_address: that.data.collageDage.detailed_address,
        address_x: that.data.collageDage.address_x,
        address_y: that.data.collageDage.address_y,
        content: contentTxt,
      }
    }, function (res) {
      that.setData({
        sendRequire: res.data
      })
      if (res.data.status == 1) {
        that.setData({
          showSubmitC: true,
        });
      } else {
        that.setData({
          showSubmitC: false,
        });
        wx.setStorage({
          key: 'ActiveData',
          data: '',
        })
      }

    }, function (res) {

    })
  },
  // 隐藏提交信息
  closeSC:function(){
    let that = this;
    that.setData({
      showSubmitC: false,
    });
  },
  // 确认
  sureBtn:function(e){
    let that =this;
    that.closeSC();
    $.openWin({
      url: '../payPage/payPage',
      data: {
        page: 'publishActivitie',
        id: that.data.sendRequire.caid,
        price: that.data.sendRequire.price,
        title: that.data.sendRequire.title,
      }
    })

  }
})